import Home from '../../components/Fragments/home';
import History from '../../components/Fragments/history';
import FooterNav from './FooterNav';
import { useState } from 'react';
import { View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import Course from '../../components/Fragments/course';
const Index = () => {
  // useLoad(() => testConnection());
  const [fragmentId, setFragmentId] = useState(0);
  const changeFragment = (index: number) => {
    setFragmentId(index);
  }
  Taro.getStorage({
    key: 'code',
    fail: () => {
      Taro.reLaunch({ url: '../selectStatus/index' })
    }
  })
  const testConnection = async () => {
    Taro.cloud.callFunction({
      name: 'test'
    }).then((ret: any) => {
      console.log(ret.result.data[0].res)//“成功连接到微信云数据库！”
    }).catch(err => {
      console.log('云数据库连接失败！', err)
    })
  }
  return <>
    <View className='index-page'>{[<Home />, <Course />, <History />][fragmentId]}</View>
    <FooterNav defaultIndex={0} onChangeIndex={changeFragment} />
  </>
}

export default Index;
